package chapter06

/**
 *
 * @author cdhuangchao3
 * @date 2023/6/9 7:48 PM
 */
object Test14_TraitMixin {
  def main(args: Array[String]): Unit = {
    val student = new Student14
    student.study()
    student.increase()
    student.play()
    student.increase()
    student.dating()
    student.increase()

    println("=" * 20)
    // 多态混入
    val studentWithTalent = new Student14 with Talent {
      override def singing(): Unit = println("student is good at singing")

      override def dancing(): Unit = println("student is good at dancing")
    }
    studentWithTalent.sayHello()
    studentWithTalent.play()
    studentWithTalent.study()
    studentWithTalent.dating()
    studentWithTalent.singing()
  }
}

trait Knowledge {
  var amount: Int = 0

  def increase(): Unit
}

trait Talent {
  def singing(): Unit
  def dancing(): Unit
}

class Student14 extends Person13 with Young with Knowledge {
  override val name: String = "student"

  override def dating(): Unit = println(s"student ${name} is dating")

  def study() = println(s"studeng ${name} is studying")

  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from student : ${name}")
  }

  override def increase(): Unit = {
    amount += 1
    println(s"student ${name} knowledge increase: ${amount}")
  }
}
